package com.rxyb.trade.gateway.controller;


import com.rxyb.core.respone.R;
import com.rxyb.trade.gateway.dto.PayOrderReq;
import com.rxyb.trade.gateway.dto.PayOrderRsp;
import com.rxyb.trade.gateway.dto.RefundOrderReq;
import com.rxyb.trade.gateway.dto.RefundOrderRsp;
import com.rxyb.trade.service.TradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * <p>
 * 交易 前端控制器
 * </p>
 *
 * @author DUYH
 * @since 2020-06-19
 */
@Controller
@RequestMapping("/trade")
public class TradeController {

    @Autowired
    private TradeService tradeService;

    /**
     * 支付
     *
     * @author duyh
     */
    @PostMapping(value = "pay", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public R<PayOrderRsp> pay(@Validated @RequestBody PayOrderReq payOrderReq) {
        return tradeService.pay(payOrderReq);
    }

    /**
     * 退款
     *
     * @author duyh
     */
    @PostMapping(value = "refund", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public R<RefundOrderRsp> refund(@Validated @RequestBody RefundOrderReq refundOrderReq) {
        return tradeService.refund(refundOrderReq);
    }

}
